<?php defined('_JEXEC') or die('Restricted access');

class ProductmanagerControllersDefault extends JControllerBase
{
	public function execute()
	{
		//We need an app and a document...
		$app = $this->getApplication();
		$document = $app->getDocument();

		//Views, layouts and stuff
		$viewName = $app->input->getWord('view', 'list');
		$viewFormat = $document->getType();
		$layoutName = $app->input->getWord('layout', 'default');

		$app->input->set('view', $viewName);

		//Layout Paths
		$paths = new SplPriorityQueue;
		$paths->insert(JPATH_COMPONENT.'/views/'.$viewName.'/tmpl', 'normal');

		$viewClass = 'ProductmanagerViews'.ucfirst($viewName).ucfirst($viewFormat);
		$modelClass = 'ProductmanagerModels'.ucfirst($viewName);

		if (false === class_exists($modelClass)) {
			$modelClass = 'ProductmanagerModelsDefault';
		}

		$view = new $viewClass(new $modelClass, $paths);
		$view->setLayout($layoutName);

		//Let's render this!
		echo $view->render();

		return true;
	}
}